package cn.cs.controller;


import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.IdWorker;
import cn.cs.pojo.UserInformationWeb;
import cn.cs.service.UserInformationWebService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/userInformationWeb")
public class UserInformationWebController {

    @Resource
    private UserInformationWebService userInformationWebService;

    /**
     * 官网收集用户信息
     * @param userName
     * @param userPhone
     * @param remarks
     * @param type 用户来源分类 1pc官网  2手机官网
     * @return
     * @throws Exception
     */
    @RequestMapping("/p/saveUserInformation")
    public Dto saveUserInformation(String userName, String userPhone, String remarks, String type)throws Exception{
        UserInformationWeb informationWeb = new UserInformationWeb();
        informationWeb.setId(IdWorker.getId());
        informationWeb.setUserName(userName);
        informationWeb.setUserPhone(userPhone);
        informationWeb.setRemarks(remarks);
        informationWeb.setType(type);
        informationWeb.setCreateDate(new Date());
        informationWeb.setState("0");
        int i = userInformationWebService.addUserInformationWeb(informationWeb);
        if(i == 1){
            return DtoUtil.returnSuccess("信息提交成功");
        }
        return DtoUtil.returnFail("提交失败,请重试", "001");
    }

    /**
     * 分页查询 用户信息
     *
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/csPlatform/getUserInformationByPage")
    public Dto getUserInformationByPage(Integer pageNumber, Integer pageSize) throws Exception {
        Map<String, Object> param = new HashMap<>();
        return DtoUtil.returnSuccess("获取成功", userInformationWebService.queryUserInformationWebPageByMap(param, pageNumber, pageSize));
    }


    /**
     * 信息处理
     * @param id
     * @param results
     * @return
     * @throws Exception
     */
    @RequestMapping("/csPlatform/updateUserInformation")
    public Dto updateUserInformation(String id, String results)throws Exception{
        UserInformationWeb informationWeb = new UserInformationWeb();
        informationWeb.setId(id);
        informationWeb.setResults(results);
        informationWeb.setState("1");
        int i = userInformationWebService.modifyUserInformationWeb(informationWeb);
        if(i == 1){
            return DtoUtil.returnSuccess("信息处理成功");
        }
        return DtoUtil.returnFail("操作失败,请重试", "001");
    }

}
